﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace VikingArcade_v2._0
{
    public class PanelDrawer : UserInterfaceControlDrawer
    {
        private Panel panel;

        public PanelDrawer(Panel panel) : base(panel)
        {
            this.panel = panel;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch)
        {
            if (panel.Visible)
            {
                if (panel.BackgroundTexture == null)
                {
                    throw new ArgumentNullException("Texture not set");
                }
                Rectangle? src;
                if (panel.SourceRectangle == null)
                {
                    src = panel.BackgroundTexture.Bounds;
                }
                else
                {
                    src = panel.SourceRectangle;
                }

                spriteBatch.Draw(panel.BackgroundTexture,
                                 new Rectangle(panel.AbsolutePosition.X, panel.AbsolutePosition.Y, panel.Size.X, panel.Size.Y), src, panel.Color);
            }
            base.Draw(spriteBatch);
        }
    }
}
